<template>
  <div class="allStyle">
    <div class="box"  v-if="carData.carImg">
      <el-row>
        <el-col :span="24">
          <p class="imgTitle">车辆图片信息</p>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="demo-image__preview">
            <el-image
              class="image"
              style="width: 300px; height: 200px"
              :src="carData.carImg[0]"
              :preview-src-list="carData.carImg"
            ></el-image>
            <el-image style="width: 300px; height: 200px" :src="carData.carImg[1]" :preview-src-list="carData.carImg"></el-image>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="box"  v-if="carData.carImg">
      <el-row>
        <el-col :span="24">
          <p class="imgTitle">身份证信息</p>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="demo-image__preview">
            <el-image
              class="image"
              style="width: 300px; height: 200px"
              :src="carData.idCardImg[0]"
              :preview-src-list="carData.idCardImg"
            ></el-image>
            <el-image style="width: 300px; height: 200px" :src="carData.idCardImg[1]" :preview-src-list="carData.idCardImg"></el-image>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="box">
      <el-row>
        <el-col :span="24">
          <p class="imgTitle">行驶证信息</p>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="demo-image__preview">
            <el-image style="width: 300px; height: 200px" :src="carData.drivingImg" :preview-src-list="[carData.drivingImg]"></el-image>
          </div>
        </el-col>
      </el-row>
    </div>
    <el-row class="btn" v-if="carData.checkState=='0'">
      <el-button type="danger" v-if="carData.rentalState=='2'" @click="this.backList" round>返回列表</el-button>
      <el-button type="danger" v-if="carData.rentalState!='2'" @click="dialogFormVisible = true" round>审核失败</el-button>
      <el-button type="success" v-if="carData.rentalState!='2'" round @click="this.checkPass">审核通过</el-button>
    </el-row>
    <el-row class="btn" v-else>
      <el-button type="success"  @click="this.backList" round>返回列表</el-button>
      <el-button v-if="carData.checkState=='2'" type="danger" @click="dialogFormVisible = true" round>失败原因</el-button>
    </el-row>
    <el-dialog title="审核失败反馈" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="审核失败原因" :label-width="formLabelWidth">
          <el-input v-if="carData.checkState=='2'" disabled v-model="carData.reason" autocomplete="off"></el-input>
          <el-input v-else v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="sureReason">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";
export default {
  created() {
    this.getOneCar();
  },
  data() {
    return {
      carData: {},
      dialogTableVisible: false,
      dialogFormVisible: false,
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: ""
      },
      formLabelWidth: "120px"
    };
  },
  methods: {
    getOneCar() {
      axios
        .get("/cars/getOneCar", { params: { _id: this.$route.query._id } })
        .then(res => {
          this.carData = res.data[0];
        });
    },
    checkPass() {
      axios
        .post("/cars/changeState", {_id: this.$route.query._id,checkState:"1" })
        .then(res => {
          this. getOneCar()
        });
    },
    backList(){
      this.$router.go(-1)
    },
    sureReason(){
      axios
        .post("/cars/changeState", {_id: this.$route.query._id,checkState:"2" ,reason:this.form.name})
        .then(res => {
          this.dialogFormVisible = false
          this. getOneCar()
        });
    }
  }
};
</script>

<style  scoped>
.allStyle{
  color: gray;
}
.image {
  margin-right: 20px;
}
.box {
  padding: 20px;
  border-bottom: 1px solid #dbdbdb;
}
.imgTitle {
  margin: 0;
  line-height: 36px;
  font-size: 18px;
  font-weight: bold;
}
.btn {
  margin-top: 20px;
}
</style>